package com.yznote.cloudesk.message.controller;

import com.yznote.cloudesk.common.Anno.CollectLogs;
import com.yznote.cloudesk.common.constants.ModuleConstant;
import com.yznote.cloudesk.common.pojo.Message;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.websocket.service.WebSocketService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/msg")
@CollectLogs(moduleName = ModuleConstant.MESSAGE_MODULE)
public class MessageController {
    @Autowired
    WebSocketService webSocketService;

    /**
     * 方法废弃
     *
     * @param message
     * @return
     */
    @ApiOperation("发送文本消息至房间")
    @PostMapping("/sendMsgToRoom")
    public Result sendMsgRoom(@RequestBody Message message) {
        Boolean res = webSocketService.sendMsgToRoom(message);
        if (res) {
            return Result.success("消息发送成功");
        } else {
            return Result.fail("消息发送失败");
        }
    }

    @ApiOperation("发送消息给好友")
    @PostMapping("/sendMsgToFriend")
    public Result sendMsgToFriend(@RequestBody Message message) {
        Boolean res = webSocketService.sendMsgToFriend(message);
        if (res) {
            return Result.success("消息发送成功");
        } else {
            return Result.fail("消息发送失败");
        }
    }

    @ApiOperation("发送消息给好友带文件")
    @PostMapping("/sendMsgToFriendWithFile")
    public Result sendMsgToFriendWithFile(@RequestParam Message message, @RequestParam MultipartFile mtf) throws Exception {

        Boolean res = webSocketService.sendMsgToFriendWithFile(message, mtf);
        if (res) {
            return Result.success("消息发送成功");
        } else {
            return Result.fail("消息发送失败");
        }
    }
}
